﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Gezel.Model
{
  /// <summary>
  /// Helper type which stores information on 
  /// a parse position. The class is immutable
  /// and therefore the fields are not encapsulated
  /// with properties.
  /// </summary>
  public class Position
  {
    private string line;
    private uint mark;
    private uint lineNumber;
    private uint columnNumber;
    private string file;

    #region Properties
    public string Line
    {
      get
      {
        return line;
      }
    }

    public uint Mark
    {
      get
      {
        return mark;
      }      
    }

    public uint LineNumber
    {
      get
      {
        return lineNumber;
      }    
    }

    public uint ColumnNumber
    {
      get
      {
        return columnNumber;
      }
    }
    
    public string File
    {
      get
      {
        return file;
      }
    }
#endregion

    /// <summary>
    /// Constructs a new Position with the specified line, mark, 
    /// line and column number.
    /// </summary>
    /// <param name="line">the line that contains this position</param>
    /// <param name="mark">the position in the input</param>
    /// <param name="lineNumber">line number</param>
    /// <param name="colNumber">column position corresponding to the mark</param>
    public Position(string line, uint mark, uint lineNumber, uint colNumber)
    {
      this.line = line;
      this.mark = mark;
      this.lineNumber = lineNumber;
      this.columnNumber = colNumber;
      this.file = "";
    }

    public Position(string line, uint mark, uint lineNumber, uint colNumber, string file) : 
      this(line, mark, lineNumber, colNumber)
    {
      this.file = file;
    }

		public bool IsGreaterThan(Position pos)
		{
			return lineNumber > pos.lineNumber && columnNumber > pos.columnNumber;
		}

		public bool IsLessThan(Position pos)
		{
			return pos.IsGreaterThan(this);
		}

		public bool IsBetween(Position start, Position end)
		{
			return start.IsLessThan(this) && end.IsGreaterThan(this);
		}

    public override string ToString()
    {
      return string.Format("line {0} in file '{1}'", LineNumber, file);
    }
  }
}
